// ECMAScript 2017;
const obj = {
    name: "jack",
    age: 18,
};
// Object.values 返回对象中所有值的数组
console.log(Object.values(obj));
// Object.entries 以数组的形式返回对象中的键值对
for (let [key, value] of Object.entries(obj)) {
    console.log(key, value);
}
// 将一个对象转换为Map类型的对象
console.log(new Map(Object.entries(obj)));

const p1 = {
    firstName: "Li",
    lastName: "Wang",
    // 向外界提供一个只读属性fullName
    get fullName() {
        return this.firstName + this.lastName;
    },
};
// assign在赋值的时候将fullName当做一个普通的属性去复制
const p2 = Object.assign({}, p1);
p2.firstName = "zce";
console.log(p2); // { firstName: 'zce', lastName: 'Wang', fullName: 'LiWang' }
// 使用Object.getOwnPropertyDescriptors 获取对象属性中完整的描述信息
const descriptors = Object.getOwnPropertyDescriptors(p1);
console.log(descriptors);
const _p2 = Object.defineProperties({}, descriptors);
_p2.firstName = "zce";
console.log(_p2); // { firstName: 'zce', lastName: 'Wang', fullName: [Getter] }

// 字符串填充方法 padStart  padEnd
// 用给定字符串填充目标字符串开始或结束位置,如果目标字符串超出给定长度,则默认显示完整目标字符串
const books = {
    html: 5,
    css: 16,
    javascript: 123,
};
for (let [key, value] of Object.entries(books)) {
    console.log(`${key.padEnd(12, "-")}|${value.toString().padStart(3, 0)}`);
}
